﻿// Copyright (c) 2012 Mokah Nnamezie & Andrew Cooper
// Neo4Net graph database - http://neo4net.codeplex.com
//
// This file is part of Neo4Net - a .Net port of the Neo4j graph database
//
// Neo4Net is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

namespace Neo4Net.GraphDb.Factory
{
    using System;
    using NUnit.Framework;

    [TestFixture]
    public class GraphDatabaseSettingTest
    {
        [Test]
        public void TestStringSetting()
        {
            GraphDatabaseSetting.StringSetting stringSetting = new GraphDatabaseSetting.StringSetting("foo_bar", GraphDatabaseSetting.ANY, "Must be a valid foo bar");

            Assert.That(stringSetting.Name, Is.EqualTo("foo_bar"));

            stringSetting.Validate("test");

            Assert.That(() => stringSetting.Validate(null), Throws.TypeOf<ArgumentNullException>());

            Assert.That(() => stringSetting.Validate(""), Throws.TypeOf<ArgumentNullException>());
        }

        [Test]
        public void TestIntegerSetting()
        {
            GraphDatabaseSetting.IntegerSetting integerSetting = new GraphDatabaseSetting.IntegerSetting("foo_bar", "Must be a valid integer", 3, 10);

            Assert.That(integerSetting.Name, Is.EqualTo("foo_bar"));

            integerSetting.Validate("5");

            integerSetting.Validate("3");

            integerSetting.Validate("10");

            Assert.That(() => integerSetting.Validate("2"), Throws.TypeOf<ArgumentOutOfRangeException>().With
                                                                    .Message.EqualTo("Minimum allowed value is:3"));

            Assert.That(() => integerSetting.Validate("11"), Throws.TypeOf<ArgumentOutOfRangeException>().With
                                                                     .Message.EqualTo("Maximum allowed value is:10"));
        }

        [Test]
        public void TestOptionsSetting()
        {
            GraphDatabaseSetting.OptionsSetting optionsSetting = new GraphDatabaseSetting.OptionsSetting("foo_bar", "option1", "option2", "option3");

            Assert.That(optionsSetting.Name, Is.EqualTo("foo_bar"));

            optionsSetting.Validate("option1");

            optionsSetting.Validate("option2");

            Assert.That(() => optionsSetting.Validate("option4"), Throws.TypeOf<ArgumentOutOfRangeException>().With
                                                                          .Message.EqualTo("Value 'option4' is not valid. Valid options are:[option1, option2, option3]"));
        }
    }
}
